import { createApp } from 'vue'
import App from './App.vue'
import router, { setupRouter } from './router'
import i18n from "@/i18n/index";
import {setupStore} from "@/store";
import {setupNaive} from "@/plugins/native";
import {setupDirectives} from "@/plugins/directives";
import {setupCustomComponents} from "@/plugins/customComponents";
import {initFunction} from '@/plugins/initFunction'
import {GoAppProvider} from '@/components/GoAppProvider/index'
import {setHtmlTheme} from "@/utils/utils";

// 全局样式
import '@/styles/pages/index.scss'
// animate.css动画
import 'animate.css/animate.min.css'
// 标尺
import 'vue3-sketch-ruler/lib/style.css'

async function appInit() {
  const goAppProvider = createApp(GoAppProvider)

  const app = createApp(App)

  // 注册常用naive-ui组件
  setupNaive(app)

  // 注册全局指令
  setupDirectives(app)

  // 注册全局自定义组件
  setupCustomComponents(app)

  // 挂载状态管理
  setupStore(app)

  // 可在全局使用message、dialog等组件，解决路由收尾、axios中使用
  goAppProvider.mount('#appProvider', true)

  // 初始化路由
  setupRouter(app)

  // 路由准备就绪后挂载APP实例
  await router.isReady()

  // 初始化默认主题
  setHtmlTheme()

  // 语言注册
  app.use(i18n)

  // 挂载到页面
  app.mount('#app', true)
  
  // 挂载到window上
  window['$vue'] = app
}

appInit().then(() => {
  initFunction()
})
